package com.dshore.messagecenter.dao.statistics;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;



@Repository
public class MemoryUsageDao {
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	//查询本日各个主题队列的值内存占用
	public List<Map<String, Object>> getEveryTopicMemory(String rq) {
		 String sql="select topicname,sum(value) as sum\r\n" + 
		 		"from (\r\n" + 
		 		"select nvl(aa.KPI_VALUE,0) as value ,bb.TOPIC_QUEUE_NAME as topicname\r\n" + 
		 		"from\r\n" + 
		 		"(select t.obj,t.KPI_VALUE,t.CREATED_TIME\r\n" + 
		 		"from  T_MR_KPI_RECORD_CURRENT t\r\n" + 
		 		"where t.kpi_CODE=(select td.DICT_CODE from T_SYS_DICT td where td.DICT_TYPE='kpi_type' and td.DICT_NAME='内存占用') \r\n" + 
		 		"and t.OBJ_TYPE=(select td.DICT_CODE from T_SYS_DICT td where td.DICT_TYPE='obj_type' and td.DICT_NAME='队列') \r\n" + 
		 		"and TO_CHAR(CREATED_TIME,'yyyy-mm-dd hh24:mi:ss')>=\'"+rq+":00\'"+"\r\n" + 
		 		"order by t.obj,t.CREATED_TIME)aa\r\n" + 
		 		"RIGHT JOIN \r\n" + 
		 		"(select a.TOPIC_QUEUE_NO,a.QUEUE_NAME,a.CREATED_TIME,x.TOPIC_QUEUE_NAME\r\n" + 
		 		"from T_MD_TOPIC_SEND a,T_MD_TOPIC x\r\n" + 
		 		"where a.DEL_FLAG=0 and a.QUEUE_NAME is not null and a.TOPIC_QUEUE_NO=x.TOPIC_QUEUE_NO) bb\r\n" + 
		 		"on aa.obj=bb.QUEUE_NAME \r\n" + 
		 		"where ROWNUM<=14\r\n" + 
		 		"ORDER BY bb.TOPIC_QUEUE_NO,bb.CREATED_TIME desc) aaa\r\n" + 
		 		"GROUP BY topicname";
		List<Map<String, Object>> list=jdbcTemplate.queryForList(sql);
		return list;
	}
}
